package tgc.edu.fhh.entity;


import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
public class SysDept {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	
	private String name;
	@ManyToOne
	@JsonIgnore
	private SysDept parent;
	private String idx1;
	
	@JsonIgnore
	@OneToMany(cascade = CascadeType.ALL,mappedBy = "parent")
	@OrderBy(value = "idx1")
	private List<SysDept> children=new ArrayList<SysDept>();
	
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getIdx1() {
		return idx1;
	}
	public void setIdx(String idx1) {
		this.idx1 = idx1;
	}
	@Transient
	public Integer getParentId() {
		return parent==null?null:parent.getId();
	}
	public void setParent(SysDept parent) {
		this.parent = parent;
	}
	public List<SysDept> getChildren() {
		return children;
	}
	public void setChildren(List<SysDept> children) {
		this.children = children;
	}
	
	public SysDept(Integer id, String name, SysDept parent, String idx1, List<SysDept> children) {
		super();
		this.id = id;
		this.name = name;
		this.parent = parent;
		this.idx1 = idx1;
		this.children = children;
	}
	public SysDept() {
		super();
	}

	
	
	
	

}
